package com.qf.controller;

import com.qf.pojo.resp.BaseResp;
import com.qf.utils.UploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Api("上传文件控制器")
@RestController
@RequestMapping("/base")
public class BaseController {
    @Autowired
    UploadUtils uploadUtils;
    @PostMapping("/upload")
    @ApiOperation(value = "文件上传方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "multipartFile", value = "文件", required = true, dataType = "MultipartFile"),
    })
    public BaseResp upLoad(@RequestParam("file")MultipartFile multipartFile){
        String upload = uploadUtils.upload(multipartFile);
        if (StringUtils.isEmpty(upload)){
            return new BaseResp().ERROR();
        }
        return new BaseResp(1,"success",upload,null);
    }
}
